package com.reabam.tryshopping.h5.reabampos;

import android.view.KeyEvent;

public class XScannerOutputUtils {

    //是否大写
    static boolean isUpperCase=false;
    static boolean isComplete=false;

    static StringBuffer stringBuffer= new StringBuffer();


    static long lastTime=0;


    //处理弹起按键, 在onKeyUp()中调用
    public static synchronized void upKey(int keyCode_android){
        if(keyCode_android== KeyEvent.KEYCODE_SHIFT_LEFT||keyCode_android== KeyEvent.KEYCODE_SHIFT_RIGHT){
            isUpperCase=false;
        }
    }


    //处理按下按键, 在onKeyDown()中调用
    public  static synchronized String downKey(int keyCode_android){
        //
        if(stringBuffer.length()!=0){
            if(isComplete){
                stringBuffer.delete(0,stringBuffer.length());
                isComplete=false;
            }else if(lastTime!=0){
                long currentTime=System.currentTimeMillis();
                if(currentTime-lastTime>(3*1000)){
                    stringBuffer.delete(0,stringBuffer.length());
                    isComplete=false;
                }
            }
        }

        lastTime=System.currentTimeMillis();

        if(keyCode_android== KeyEvent.KEYCODE_ENTER){
            isComplete=true;
            return stringBuffer.toString();
        }else if(keyCode_android== KeyEvent.KEYCODE_SHIFT_LEFT||keyCode_android== KeyEvent.KEYCODE_SHIFT_RIGHT){
            isUpperCase=true;
        }else if(keyCode_android== KeyEvent.KEYCODE_0){
            stringBuffer.append("0");
        }else if(keyCode_android== KeyEvent.KEYCODE_1){
            stringBuffer.append("1");
        }else if(keyCode_android== KeyEvent.KEYCODE_2){
            stringBuffer.append("2");
        }else if(keyCode_android== KeyEvent.KEYCODE_3){
            stringBuffer.append("3");
        }else if(keyCode_android== KeyEvent.KEYCODE_4){
            stringBuffer.append("4");
        }else if(keyCode_android== KeyEvent.KEYCODE_5){
            stringBuffer.append("5");
        }else if(keyCode_android== KeyEvent.KEYCODE_6){
            stringBuffer.append("6");
        }else if(keyCode_android== KeyEvent.KEYCODE_7){
            stringBuffer.append("7");
        }else if(keyCode_android== KeyEvent.KEYCODE_8){
            stringBuffer.append("8");
        }else if(keyCode_android== KeyEvent.KEYCODE_9){
            stringBuffer.append("9");
        }else if(keyCode_android== KeyEvent.KEYCODE_A){
            if(isUpperCase){
                stringBuffer.append("A");
            }else{
                stringBuffer.append("a");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_B){
            if(isUpperCase){
                stringBuffer.append("B");
            }else{
                stringBuffer.append("b");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_C){
            if(isUpperCase){
                stringBuffer.append("C");
            }else{
                stringBuffer.append("c");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_D){
            if(isUpperCase){
                stringBuffer.append("D");
            }else{
                stringBuffer.append("d");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_E){
            if(isUpperCase){
                stringBuffer.append("E");
            }else{
                stringBuffer.append("e");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_F){
            if(isUpperCase){
                stringBuffer.append("F");
            }else{
                stringBuffer.append("f");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_G){
            if(isUpperCase){
                stringBuffer.append("G");
            }else{
                stringBuffer.append("g");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_H){
            if(isUpperCase){
                stringBuffer.append("H");
            }else{
                stringBuffer.append("h");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_I){
            if(isUpperCase){
                stringBuffer.append("I");
            }else{
                stringBuffer.append("i");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_J){
            if(isUpperCase){
                stringBuffer.append("J");
            }else{
                stringBuffer.append("j");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_K){
            if(isUpperCase){
                stringBuffer.append("K");
            }else{
                stringBuffer.append("k");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_L){
            if(isUpperCase){
                stringBuffer.append("L");
            }else{
                stringBuffer.append("l");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_M){
            if(isUpperCase){
                stringBuffer.append("M");
            }else{
                stringBuffer.append("m");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_N){
            if(isUpperCase){
                stringBuffer.append("N");
            }else{
                stringBuffer.append("n");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_O){
            if(isUpperCase){
                stringBuffer.append("O");
            }else{
                stringBuffer.append("o");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_P){
            if(isUpperCase){
                stringBuffer.append("P");
            }else{
                stringBuffer.append("p");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_Q){
            if(isUpperCase){
                stringBuffer.append("Q");
            }else{
                stringBuffer.append("q");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_R){
            if(isUpperCase){
                stringBuffer.append("R");
            }else{
                stringBuffer.append("r");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_S){
            if(isUpperCase){
                stringBuffer.append("S");
            }else{
                stringBuffer.append("s");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_T){
            if(isUpperCase){
                stringBuffer.append("T");
            }else{
                stringBuffer.append("t");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_U){
            if(isUpperCase){
                stringBuffer.append("U");
            }else{
                stringBuffer.append("u");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_V){
            if(isUpperCase){
                stringBuffer.append("V");
            }else{
                stringBuffer.append("v");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_W){
            if(isUpperCase){
                stringBuffer.append("W");
            }else{
                stringBuffer.append("w");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_X){
            if(isUpperCase){
                stringBuffer.append("X");
            }else{
                stringBuffer.append("x");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_Y){
            if(isUpperCase){
                stringBuffer.append("Y");
            }else{
                stringBuffer.append("y");
            }
        }else if(keyCode_android== KeyEvent.KEYCODE_Z){
            if(isUpperCase){
                stringBuffer.append("Z");
            }else{
                stringBuffer.append("z");
            }
        }


        return null;
    }




}
